capture	log close
log using MAR02-SampDiag-UNODC,  replace text

//  program:    Stata 
//  task:       Sample and diagnostics 
//  project:    Markets  

version
clear all
macro drop _all
set linesize 80
set more off
local tag " 05-05-25"
local file "MAR02-SampDiag-UNODC"
local note "|`tag' | `file'"
local opt "noparen sideway excel noaster  bdec(2)  sdec(2)  pdec(3)   adec(2) e(r2) stats(coef se pval)"
local dv "lrhom_un"
local iv "fraser"
local cont "infantmort  edu unemp  popdense perurban  sexratio"
local cont2 "infantmort  gini edu unemp  popdense perurban  sexratio"

//	#0
//	loading data 
use MAR01-DataClean-UNODC, clear 

//	#1
//	getting sample 
gen lrhom_un=log(rhom_un)
xtset CID year 
xtreg `dv' `iv' `cont', fe 
tab nation if e(sample)==1
gen sample=1 if e(sample)==1 
/* Nations to drop (n<5)
Angola
Belarus
Belgium
Brunei Darussalam
Cambodia
Ethiopia
Guinea-Bissau
Indonesia
Iran (Islamic Republic of)
Lesotho
Mauritania
Niger
Nigeria
Saudi Arabia
Tajikistan
Timor-Leste
Yemen*/ 
replace sample=. if nation=="Angola"
replace sample=. if nation=="Belarus"
replace sample=. if nation=="Belgium"
replace sample=. if nation=="Brunei Darussalam"
replace sample=. if nation=="Cambodia"
replace sample=. if nation=="Ethiopia"
replace sample=. if nation=="Guinea-Bissau"
replace sample=. if nation=="Indonesia"
replace sample=. if nation=="Iran (Islamic Republic of)"
replace sample=. if nation=="Lesotho"
replace sample=. if nation=="Mauritania"
replace sample=. if nation=="Niger"
replace sample=. if nation=="Nigeria"
replace sample=. if nation=="Saudi Arabia"
replace sample=. if nation=="Tajikistan"
replace sample=. if nation=="Timor-Leste"
replace sample=. if nation=="Yemen"

tab nation if rhom_un==0
replace sample=. if rhom_un==0

tab nation if sample==1
drop if sample!=1

//	#2
//	normal 
* qladder rhom_un 
label var lrhom_un "Ln Homicide Victimization Rates" 
note lrhom_un: `note'. 

//	#3
//	station 
xtunitroot fisher rhom_un, dfuller lags(0) 

foreach var in `iv' `cont'  {
	xtunitroot fisher `var', dfuller lags(0) 
	}
	
//	#4
//  Autocorrelation 
xtserial lrhom_un `iv' `cont'
xtserial lrhom_un `iv' `cont2'

//	#5
//	Cross-Sectional Dependence 
xtreg rhom_un `iv' `cont' , fe
* xtcsd, pesaran abs
xtreg lrhom_un `iv' `cont2' , fe
* xtcsd, pesaran abs

/* Neither had enough obs */ 

//	#6
//	Homoscedastic 
xtreg lrhom_un `iv' `cont' , fe
xttest3 

//	#7
//	Final model 
xtreg lrhom_un `iv' `cont', fe vce(robust) 
outreg2 using `file', replace `opt' 

//	#8
//	save and close 
note:  Completed sample and pre-model diagnostics | `note'. 
notes
save `file'.dta, replace 
log close 
//